package com.zhicheng.controller;

import com.zhicheng.pojo.ShoppingCart;
import com.zhicheng.pojo.dto.ShoppingCartDTO;
import com.zhicheng.pojo.result.Result;
import com.zhicheng.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车相关接口")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    @GetMapping("/list")
    @ApiOperation("查询购物车")
    public Result<List<ShoppingCart>> list(){
        List<ShoppingCart> list = shoppingCartService.showShoppingCart();
        return Result.success(list);
    }

    @PutMapping("/update")
    @ApiOperation("修改购物车")
    public Result update(@RequestBody List<ShoppingCart> shoppingCarts){
        shoppingCartService.updateShoppingCart(shoppingCarts);
        return Result.success();
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除购物车")
    public Result delete(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppingCartService.deleteShoppingCart(shoppingCartDTO);
        return Result.success();
    }

}
